﻿

using System;
using Sharp.Portal.Other;

namespace Sharp.Portal
{
    /// <summary>
    /// 数据处理实体
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class DataHandlerAttribute : System.Attribute
    {
        /// <summary>
        /// 数据处理实体
        /// </summary>
        public DataHandlerAttribute()
        {
            this.Mode = "Details";
            this.Title = "浏览";
            this.Order = 0;
            this.HasWindow = true;
        }

        /// <summary>
        /// 数据处理实体
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="title">标题</param>
        /// <param name="orderId">The order identifier.</param>
        public DataHandlerAttribute(string mode, string title, int orderId)
        {
            this.Mode = mode;
            this.Title = title;
            this.Order = orderId;
        }
        /// <summary>
        /// 数据处理实体
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="title"></param>
        /// <param name="orderId"></param>
        /// <param name="onClientClick"></param>
        public DataHandlerAttribute(string mode, string title, int orderId, string onClientClick)
            : this(mode, title, orderId)
        {
            OnClientClick = onClientClick;
        }

        /// <summary>
        /// 模式
        /// </summary>
        public string Mode { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int Order { get; set; }

        /// <summary>
        /// 是否有窗口
        /// </summary>
        public bool HasWindow { get; set; }

        /// <summary>
        /// 宽度
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// 高度
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// Url
        /// </summary>
        public string Url { get; set; }


        /// <summary>
        /// Iframe Style
        /// </summary>
        /// <remarks>0：以iframe打开链接；1：以窗体打开链接；2：url的资源是否当作js来执行</remarks>
        public int IsIFrameStyle { get; set; }

        /// <summary>
        /// 客户端点击事件
        /// </summary>
        public string OnClientClick { get; set; }
        /// <summary>
        /// 图标
        /// </summary>
        public string Icon { get; set; }
        /// <summary>
        /// Action名称
        /// </summary>
        /// <example>可以接受GetPaged或者GetPaged,User。它会自己转换为Url.Action相关形式</example>
        public string UrlAction { get; set; }

        /// <summary>
        /// 获取定义数据
        /// </summary>
        /// <returns></returns>
        public ToolButtonInfo GetHandler()
        {
            ToolButtonInfo info = new ToolButtonInfo()
            {
                Mode = this.Mode,
                Title = this.Title,
                HasWindow = this.HasWindow,
                Height = this.Height,
                Width = this.Width,
                Url = this.Url,
                UrlAction = this.UrlAction.IsNotNullOrEmpty() ? this.UrlAction : this.Mode,
                IsIFrameStyle = this.IsIFrameStyle,
                OnClientClick = this.OnClientClick,
                Icon = this.Icon
            };
            return info;
        }
    }
}